package com.schoolhostptail.controller;

import com.schoolhostptail.entity.Stutj;
import com.schoolhostptail.entity.Teatj;
import com.schoolhostptail.entity.view.StutjView;
import com.schoolhostptail.entity.view.TeatjView;
import com.schoolhostptail.qpage.QPage;
import com.schoolhostptail.service.IStutjService;
import com.schoolhostptail.service.ITeatjService;
import com.schoolhostptail.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * 教师体检控制层入口
 */
@Controller
@RequestMapping("/api/teatj")
public class TeatjController {

    /**
     * 业务层
     */
    @Autowired
    private ITeatjService service;

    /**
     * 路由地址
     */
    public String prefix = "/admin/teatj";


    /**
     * 进入列表页面
     * @return
     */
    @RequestMapping("/index")
    public String index(){
        return prefix+"/index";
    }


    /**
     * 获取所有的列表
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public Result getList(QPage qPage, TeatjView obj, HttpSession session) {
        return Result.reOk("查询成功",this.service.getList(qPage,obj));
    }


    /**
     * 进入新增页面
     * @return
     */
    @RequestMapping("/add")
    public String add(){
        return prefix+"/add";
    }

    /**
     * 新增保存
     * @return
     */
    @RequestMapping("/insert")
    @ResponseBody
    public Result insert(Teatj obj) {
        obj.setCtime(new Date());
        obj.setTjdate(new Date());
        return this.service.insert(obj);
    }

    /**
     * 进入编辑页面
     * @return
     */
    @RequestMapping("/edit")
    public String edit(){
        return prefix+"/edit";
    }

    /**
     * 进入查询页面
     * @return
     */
    @RequestMapping("/search")
    public String search(){
        return prefix+"/search";
    }

    /**
     * 根据ID获取信息
     * @param id
     * @return
     */
    @RequestMapping("/getById")
    @ResponseBody
    public Result getById(Integer id) {
        return Result.reOk("查询成功",this.service.getById(id));
    }

    /**
     * 编辑保存
     * @return
     */
    @RequestMapping("/updates")
    @ResponseBody
    public Result updates(Teatj obj) {
        obj.setUtime(new Date());
        return this.service.updates(obj);
    }


    /**
     * 删除保存
     * @return
     */
    @RequestMapping("/deleteId")
    @ResponseBody
    public Result deleteId(Integer id) {
        return this.service.deleteId(id);
    }



}
